#include "RotationalProjectionStatisticsModel.h"

#include "core/AppDirectory.h"

namespace {
const QString UserFilename = "pcl.rotational_projection_statistics_model.json";
}

RotationalProjectionStatisticsModel::RotationalProjectionStatisticsModel()
    : BasePclModel()
{
    setPclHelpPage("https://pcl.readthedocs.io/projects/tutorials/en/master/rops_feature.html");
}

RotationalProjectionStatisticsModel& RotationalProjectionStatisticsModel::get()
{
    static RotationalProjectionStatisticsModel instance;
    if (instance.filename().isEmpty()) {
        instance.setFilename(AppDirectory::get().getAppDocFile(UserFilename));
        instance.load();
    }
    return instance;
}

void RotationalProjectionStatisticsModel::fromJson(const QJsonObject& json, QStringList& errorList)
{
    BasePclModel::fromJson(json, errorList);

    pcdFile_ = json["pcdFile"].toString(pcdFile_);
    indicesFile_ = json["indicesFile"].toString(indicesFile_);
    trianglesFile_ = json["trianglesFile"].toString(trianglesFile_);
    radiusSearch_ = json["radiusSearch"].toDouble(radiusSearch_);
    supportRadius_ = json["supportRadius"].toDouble(supportRadius_);
    numberOfPartitionBins_ = json["numberOfPartitionBins"].toInt(numberOfPartitionBins_);
    numberOfRotations_ = json["numberOfRotations"].toInt(numberOfRotations_);
}

QJsonObject RotationalProjectionStatisticsModel::toJson() const
{
    QJsonObject json = BasePclModel::toJson();

    json.insert("pcdFile", pcdFile_);
    json.insert("indicesFile", indicesFile_);
    json.insert("trianglesFile", trianglesFile_);
    json.insert("radiusSearch", radiusSearch_);
    json.insert("supportRadius", supportRadius_);
    json.insert("numberOfPartitionBins", numberOfPartitionBins_);
    json.insert("numberOfRotations", numberOfRotations_);
    return json;
}
